﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using System.Data.Sql;
using System.Data.SqlClient;
using CNotebook;

namespace NotebookS2
{
    public partial class M_ChartOfAccount : RibbonForm
    {
        public string FatherAccntCode { get; set; }
        public string ActiveUserID { get; set; }

        public M_ChartOfAccount()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }


        private void M_ChartOfAccount_Load(object sender, EventArgs e)
        {
            ChartOfAccountManager oManager = new ChartOfAccountManager();
            DataTable oTable = new DataTable();
            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            oTable = oManager.GetChartOfAccountByAccountType(true);
            cmbFatherAccount.Properties.DataSource = oTable;
            cmbFatherAccount.Properties.DisplayMember = "AcctName";
            cmbFatherAccount.Properties.ValueMember = "AcctCode";

            DevExpress.XtraEditors.Controls.LookUpColumnInfo col;

            col = new DevExpress.XtraEditors.Controls.LookUpColumnInfo("AcctCode", 100);

            col.SortOrder = DevExpress.Data.ColumnSortOrder.Ascending;

            cmbFatherAccount.Refresh();
            cmbFatherAccount.Visible = true;

            

            oManager.Close();
        }


        private void btnAdd_Click_1(object sender, EventArgs e)
        {
            ChartOfAccountManager oManager = new ChartOfAccountManager();
            ChartOfAccountUnit oUnit = new ChartOfAccountUnit();

            #region Inserting values in Unit Class
            if (chkIsAcctTitle.Checked == true)
            {
                oUnit.IsAccountTitle = "Y";
            }
            else
            {
                oUnit.IsAccountTitle = "N";   
            }

            oUnit.AcctCode = txtAccountCode.Text;
            if (cmbFatherAccount.EditValue != null)
            {
                oUnit.FatherAcctCode = cmbFatherAccount.EditValue.ToString();
            }
            else
            {
                oUnit.FatherAcctCode = "N/A";
            }
            oUnit.AcctName = txtAccountName.Text;
            oUnit.AcctStatus = "Active";
            oUnit.AcctType = cmbAccntType.Text;

            oUnit.DateCreated = System.DateTime.Now.ToString();
            oUnit.CreatedBy = this.ActiveUserID;
            oUnit.DateModified = System.DateTime.Now.ToString();
            oUnit.ModifiedBy = this.ActiveUserID;
            #endregion

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            oManager.AddChartOfAccount(oUnit);

            oManager.Close();




            MessageBox.Show("Document saved successfully!","TRCI - Message",MessageBoxButtons.OK);

            this.Close();
        }

        private void btnCancel_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

       

    }
}
